<!DOCTYPE html>
<html>
<head>
    <title><%= title %></title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="/bootstrap/dist/css/bootstrap.min.css">
    <script src="/jquery/dist/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script defer src="/bootstrap/dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>

    <link rel='stylesheet' href='/stylesheets/style.min.css' />
</head>
<body>
<nav class="navbar navbar-default c-header" role="navigation">
    <div class="navbar-header">
        <a href="/" class="navbar-brand">个人博客</a>
    </div>
    <ul class="nav navbar-nav navbar-left hidden-xs">
        <li id="nav-posts"><a href="/posts">文章列表</a></li>
        <!--<li id="nav-starter"><a href="#">新手入门</a></li>-->
        <!--<li id="nav-npms"><a href="#">Npms</a></li>-->
    </ul>
    <ul class="nav navbar-nav navbar-right hidden-xs" style="margin-right: 15px">
        <% if(!locals.user) { %>
            <li><a href="<%= authVisitUrl %>">登陆</a></li>
        <% } else { %>
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                消息提醒
                <span class="badge badge-important" id="unread-badge" style="background-color: lightcoral"></span>
                <b class="caret"></b>
            </a>
            <ul class="dropdown-menu" id="unread-notification"></ul>
        </li>
        <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                <%= user.name %>
                <b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
                <!--<li><a href="#">jmeter</a></li>-->
                <!--<li><a href="#">EJB</a></li>-->
                <!--<li><a href="#">Jasper Report</a></li>-->
                <!--<li class="divider"></li>-->
                <li><a href="/github/logout">退出</a></li>
            </ul>
        </li>
        <% } %>
    </ul>
</nav>

<!-- 获取黄金价格 -->
<script>
    $(function(){
        $('#getGoldPrice').on('click',function(){
            $.ajax({
                type: "GET",
                url: "/goldPrice",
                success: function(data){
                    $('#showGoldPrice').html(data.price/100);
                },
                error: function(){
                    $('#showGoldPrice').html('--');
                }
            });
        }).trigger('click');
        setInterval(function(){
            $('#getGoldPrice').trigger('click');
        }, 10000);


        $.ajax({
            type: "GET",
            url: "/notifications/api/unread",
            success: function(data){
                if(data.notifictions){
                    $('#unread-notification').children('li').remove();
                    if (data.notifictions && data.notifictions.length > 0){
                        data.notifictions.forEach(function(notification){
                            $('#unread-notification').append('<li><a class="unread-item" href="/posts/show/' + notification.post + '?notificationId=' + notification._id + '">' + notification.content + '</a></li>');
                            $('#unread-badge').text(data.notifictions.length);
                        });
                    }else {
                        $('#unread-notification').append('<li><span class="btn btn-link">无消息</span></li>');
                    }

                }
            },
            error: function(){
                return console.log('请求失败');
            }
        });

    });
</script>


